﻿package {
	import flash.display.Sprite;
	import flash.net.*;
	import flash.xml.*;
	import flash.events.*;
	import flash.text.*;
	
	public class Main extends Sprite {
		
		// Constants:
		// Public Properties:
		// Private Properties:
		private var xmlLoader:URLLoader	= new URLLoader();
		private var xmlItemData:XML		= new XML();
		
		private var items:Array			= new Array();
		private var itemBox:TextField	= new TextField();
	
		// Initialization:
		public function Main() {
			xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
			xmlLoader.load(new URLRequest("testlog.xml"));
		}
	
		// Public Methods:
		// Protected Methods:
		private function LoadXML(e:Event):void {
			xmlItemData	= new XML(e.target.data);
			ParseXML(xmlItemData);
			showItems();
		}
		
		private function ParseXML(xmlData:XML):void {
			var allItems:XMLList	= xmlData.item;
			var tmp:Item;
			for each(var item:XML in allItems) {
				tmp	= new Item(item);
				items.push(tmp);
			}
		}
		
		private function showItems():void {
			var displayFormat:TextFormat	= new TextFormat();
				displayFormat.font			= "Arial";
				displayFormat.color			= 0x000000;
				displayFormat.size			= 11;
				displayFormat.bold			= true;
			
			itemBox.text		= setText(items[0]);
			itemBox.setTextFormat(displayFormat);
			itemBox.autoSize	= TextFieldAutoSize.LEFT;
			itemBox.x			= 5;
			itemBox.y			= 5;
			
			addChild(itemBox);
		}
		
		private function setText(itm:Item):String {
			var returnString:String;
			returnString	= itm.quality + " " + itm.subType + " (" + itm.baseType + "): " + itm.itemName + "\n";
			for (var i:int = 0; i < itm.attributes.length; i++) {
				returnString	+= itm.attributes[i][0] + ": " + itm.attributes[i][1] + "\n";
			}
			return returnString;
		}
	}
	
}